package HLLib.base;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLLibObject;

public class HLIntListEncrypted extends HLLibObject {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_BASE, HLClassManager_H.LIB_CLASS_BASE_IntListEncrypted);
    }

    private int key = 13684;

    public int[] items;

    private HLIntList list;

    public HLIntListEncrypted() {
        items = new int[0];
        list = new HLIntList();
        key = HLTime.CurrentSecond() + 12345;
    }

    public HLIntListEncrypted(int count) {
        items = new int[count];
        list = new HLIntList(count);
    }

    public void SetCount(int count) {
        if (items.length < count) {
            items = HLIntList.Resize(items, items.length, count - items.length);
        }
        list.SetCount(count);
        for (int i = 0; i < count; i++) {
            SetItem(i, 0);
        }
    }

    public void SetItem(int index, int value) {
        items[index] = ((~value) ^ key);
        list.SetItem(index, value);

    }

    public int GetItem(int index) {
        return ~(items[index] ^ key);
    }

    public void Add(int item) {
        Resize(items.length, 1);
        SetItem(items.length - 1, item);
        list.Add(item);
    }

    public void Clear() {
        items = new int[0];
        list.Clear();
    }

    public int Count() {
        return items.length;
    }

    public void Insert(int index, int value) {
        Resize(index, 1);
        items[index] = value;
        list.Insert(index, value);
    }

    public void RemoveAt(int index) {
        Resize(index, -1);
        list.RemoveAt(index);
    }

    public void Resize(int index, int count) {
        items = HLIntList.Resize(items, index, count);
        list.Resize(index, count);
    }

    public HLIntList GetIntList() {
        HLIntList intList = new HLIntList(items);
        return intList;
    }

    public boolean IsCheat() {
        for (int i = 0; i < items.length; i++) {
            if (list.GetItem(i) != GetItem(i)) {
                return true;
            }
        }
        return false;
    }
}
